<template>
	<view>

		<view class="accountList_box">
			<view class="accountList_con">
				<view class="accountItem" v-for="(item,index) in accountList" :key="index"
					@click="accountClick(item.id)">
					<view class="accountHead_con">
						<view class="accountDate">{{item.work_date}}</view>
						<!-- status:0未处理、1已处理、2已拒绝 -->
						<view class="accountStatus" v-if="item.status==0">{{item.status_str}}</view>
						<view class="accountStatus accountSuccess" v-if="item.status==1">{{item.status_str}}</view>
						<view class="accountStatus accountFail" v-if="item.status==2">{{item.status_str}}</view>
					</view>
					<view class="accountBody_con">
						{{item.userInfo.name}}修改{{item.work_date}}记工
					</view>
				</view>
			</view>

			<!-- 空数据 -->
			<view class="dataEmpty_con" v-if="accountList.length==0">
				<u-empty></u-empty>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 默认工地信息
				defaultWorksite: JSON.parse(uni.getStorageSync('defaultWorksite')),

				month: '',

				// 账目日志
				accountList: [],

				// 分页
				pages: 1,
				limit: 10,
				last_page: 0,

				// 加载更多
				loadStatus: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '上拉或点击加载更多',
					loading: '努力加载中',
					nomore: '没有更多了'
				},
			};
		},
		onLoad(option) {
			// uni.showLoading({
			// 	title: '加载中'
			// });
			if (option.month) {
				this.month = option.month;
			}
		},
		onShow() {
			var _this = this;
			_this.getAccountList();
		},
		onReady() {

		},
		onReachBottom() {
			var _this = this;
			_this.loadmore();
		},
		methods: {
			// 获取日志列表
			getAccountList() {
				var _this = this;
				_this.$u.get('/api/project.salary/workLog', {
					project_id: _this.defaultWorksite.project_id,
					month: _this.month,
					// member_id: _this.defaultWorksite.member_id,
					member_id: '305',
				}).then(res => {
					uni.hideLoading();
					var accountList = _this.accountList;
					if (_this.pages == 1) {
						accountList = [];
					}
					_this.accountList = accountList.concat(res.data);

					// 分页状态更新
					_this.last_page = res.extend.last_page;
					if (_this.pages >= _this.last_page) _this.loadStatus = 'nomore';
					else _this.loadStatus = 'loadmore';
				}).catch(res => {
					console.log(res);
				})
			},

			// 点击加载更多
			loadmore() {
				var _this = this;
				if (_this.pages >= _this.last_page) return;
				_this.loadStatus = 'loading';
				_this.pages++;

				setTimeout(() => {
					if (_this.pages >= _this.last_page) _this.loadStatus = 'nomore';
					else _this.loadStatus = 'loading';
					uni.showLoading({
						title: '加载中'
					});
					_this.getAccountList();
				}, 2000)
			},

			// 账目详情
			accountClick(id) {
				uni.navigateTo({
					url: './accountDetail?id=' + id
				})
			},

		}
	}
</script>

<style lang="scss" scoped>
	.accountList_box {
		padding: 0 30rpx;
	}

	.accountList_con {
		padding-top: 20rpx;
		overflow: hidden;
	}

	.accountItem {
		background: #ffffff;
		border-radius: 10rpx;
		overflow: hidden;
		margin-bottom: 20rpx;
	}

	.accountHead_con {
		padding: 30rpx;
		border-bottom: 1rpx solid #eee;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.accountDate {
		font-size: 26rpx;
	}
	
	.accountStatus{
		width: 114rpx;
		height: 42rpx;
		line-height: 42rpx;
		text-align: center;
		font-size: 24rpx;
		border-radius: 6rpx;
		overflow: hidden;
	}

	.accountSuccess {
		color: $uni-color-active;
		border: 2rpx solid $uni-color-active;
	}

	.accountFail {
		color: #FF4241;
		border: 2rpx solid #FF4241;
	}

	.accountBody_con {
		padding: 30rpx;
		font-size: 32rpx;
		font-weight: bold;
		overflow: hidden;
	}
</style>
